/**
 * @File		: DebugWindow.java
 * @Subject		: Displays debug information
 * @author 		: Isaac Parenteau	locus2k@gmail.com
 * @Date		: October 12th, 2011
 * @Licence		: Written under GNU LGPL
 */
package mil.cdc.windows;

import java.awt.Color;
import java.awt.Font;
import java.awt.Toolkit;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ScrollPaneConstants;
import javax.swing.text.DefaultCaret;

import mil.cdc.listeners.CustomMouseListener;
import mil.cdc.utils.CDCConstants;

import org.dyno.visual.swing.layouts.Bilateral;
import org.dyno.visual.swing.layouts.Constraints;
import org.dyno.visual.swing.layouts.GroupLayout;
import org.dyno.visual.swing.layouts.Leading;

//VS4E -- DO NOT REMOVE THIS LINE!
public class DebugWindow extends JFrame {
	
	private static final long serialVersionUID = 1L;
	private JTextArea debugArea;
	private JScrollPane debugPane;
	private JButton closeBtn;
	
	public DebugWindow() {
		initComponents();
	}

	private void initComponents() {
		setTitle("Debug Window");
		setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/mil/cdc/data/ico/af.gif")));
		setFont(new Font("Dialog", Font.PLAIN, 12));
		setForeground(Color.black);
		setLayout(new GroupLayout());
		add(getDebugPane(), new Constraints(new Bilateral(13, 12, 22), new Leading(13, 395, 10, 10)));
		add(getJButton0(), new Constraints(new Bilateral(102, 101, 81), new Leading(420, 12, 12)));
		setResizable(false);
		setSize(303, 507);
	}

	private JButton getJButton0() {
		if (closeBtn == null) {
			closeBtn = new JButton();
			closeBtn.setText("Close");
			closeBtn.addMouseListener(new CustomMouseListener(this, CDCConstants.CLOSE));
		}
		return closeBtn;
	}

	private JScrollPane getDebugPane() {
		if (debugPane == null) {
			debugPane = new JScrollPane();
			debugPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
			debugPane.setFocusable(false);
			debugPane.setViewportView(getJTextArea0());
		}
		return debugPane;
	}

	private JTextArea getJTextArea0() {
		if (debugArea == null) {
			debugArea = new JTextArea();
			debugArea.setLineWrap(true);
			debugArea.setWrapStyleWord(true);
			debugArea.setEnabled(false);
			debugArea.setFocusable(false);
			debugArea.setDisabledTextColor(new Color(51, 51, 51));
			debugArea.setAutoscrolls(true);
			
			DefaultCaret caret = (DefaultCaret)debugArea.getCaret();
			caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
		}
		return debugArea;
	}

	/**
	 * Adds a message to the debug window
	 * @param message Message to add
	 */
	public void addMessage(String message){
		debugArea.append(message + "\n");
	}
	
	/**
	 * Clears the debug window
	 */
	public void resetMessage(){
		debugArea.setText("");
	}

}
